package com.carter.springframework.core.type;

import com.carter.springframework.core.annotation.MergedAnnotation;
import com.carter.springframework.core.annotation.MergedAnnotationSelectors;
import com.carter.springframework.core.annotation.MergedAnnotations;

import java.lang.annotation.Annotation;
import java.util.Map;

public interface AnnotatedTypeMetadata {
    MergedAnnotations getAnnotations();

    default Map<String, Object> getAnnotationAttributes(String annotationName, boolean classValuesAsString) {

        MergedAnnotation<Annotation> annotation = getAnnotations().get(annotationName, null, MergedAnnotationSelectors.firstDirectlyDeclared());
        if (!annotation.isPresent()) {
            return null;
        }
        return annotation.asAnnotationAttributes(MergedAnnotation.Adapt.values(classValuesAsString, true));
    }
    default Map<String, Object> getAnnotationAttributes(String annotationName) {
        return getAnnotationAttributes(annotationName, false);
    }
}
